import { useRef, useState } from 'react';

import { allGet } from '@/services/pc';
import storage from '@/utils/storage';
import { TOKEN } from '@/common/const';

export default () => {
  const [lecturer, setLecturerData] = useState<any>({});
  const [isSinged, setIsSinged] = useState<boolean>(false);
  const isInit = useRef(false);
  // 获取讲师资料状态数据
  const getLecturer = async () => {
    const token = storage.get(TOKEN);
    if (!token?.value) return;
    const response = await allGet({
      params: { mod: 'teacher', do: 'cooperate', version: 'pc1.0' },
    });
    const data = {
      ...(response?.data ?? {}),
    };
    isInit.current = true;
    //
    if (response?.data?.teacher?.contract?.signStatus == 3) {
      setIsSinged(true);
    }
    setLecturerData(data);
  };

  const setLecturer = (data: Record<string, any>) => {
    setLecturerData({
      ...lecturer,
      ...data,
    });
  };

  return {
    isSinged,
    lecturer,
    getLecturer,
    setLecturer,
    isInit,
  };
};
